package tests;

import Common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

import java.io.IOException;

public class loginPage extends Utils {
    public static String url = "http://127.0.0.1:8080/blogin.html";
    public loginPage() {
        super(url);
    }
    //检查页面是否加载成功
    public void loginPageRight() {
        //通过查看页面元素是否存在来检查页面加载成功与否
        driver.findElement(By.cssSelector("body > div.login-box.row > div.img-box.col-sm-6.col-md-6.col-lg-7.col-xl-7 > img"));
        //登陆输入框
        driver.findElement(By.cssSelector("#phoneNumber"));
    }

    //检查登录功能---成功登录
    public void LoginSuc() throws IOException, InterruptedException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#phoneNumber")).clear();
        driver.findElement(By.cssSelector("#phoneNumber")).sendKeys("15879007369");
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#loginForm > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert "http://127.0.0.1:8080/admin.html".equals(currentUrl);
//        getScreenShot(this.getClass().getName());
    }

    //检查登录功能---登录失败(电话号码错误)
    public void LoginFail() throws InterruptedException, IOException {
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#phoneNumber")).clear();
        driver.findElement(By.cssSelector("#phoneNumber")).sendKeys("123456789");
        driver.findElement(By.cssSelector("#password")).clear();
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#loginForm > button")).click();
        String currentUrl = driver.getCurrentUrl();
        assert url.equals(currentUrl);
//        getScreenShot(this.getClass().getName());
    }


}
